<?php

/**
 * entityImage actions.
 *
 * @package    Redsea20
 * @subpackage entityImage
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class entityImageActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
      $userid = 0;
      /**
       * IF PASSED PARAMETER IS NULL/0, THEN GET THE ID FROM SESSION
       */
      if($this->getRequestParameter('entityid') != null && $this->getRequestParameter('entityid') != '0')
      {
          $userid = $this->getRequestParameter('entityid');
      }
      else
      {
          $userid = $this->getUser()->getAttribute('userid');
      }

      $entityList = Doctrine_Core::getTable('Entity');
      $entity = $entityList->find($userid);
      //$entity = $entityList->find($this->getUser()->getAttribute('userid'));

      // IF there is no image then show default image
      if($entity["picture"] == null)
      {
          $image_location = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'no_profile_picture.png';
          $image_size = getimagesize($image_location);
          $image_type = $image_size['mime'];
          $data = file_get_contents($image_location);
          //$image_data = addslashes($data);
          header("Content-type: ".$image_type);

          echo $data;
      }
      else
          echo $entity["picture"];


      return sfView::NONE;
  }
}
